﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EmptoolWebApp.Helpers
{
    public class ClaimHelper : BaseHelper
    {
        public static string GetClaim(string claimType, System.Security.Principal.IIdentity identity)
        {
            string result = string.Empty;

            System.Security.Claims.ClaimsIdentity claimsIdentity = identity as System.Security.Claims.ClaimsIdentity;
            if (claimsIdentity == null)
                return result;

            System.Security.Claims.Claim claim = claimsIdentity.Claims.Where(c => c.Type == claimType).FirstOrDefault();
            if (claim == null)
                return result;

            return claim.Value;

        }

        public static string GetClaim(string claimType)
        {
            System.Security.Claims.ClaimsPrincipal principal = System.Security.Claims.ClaimsPrincipal.Current;

            return GetClaim(claimType, principal.Identity);
        }

        public static string GetGivenName(System.Security.Principal.IIdentity identity)
        {
            return ClaimHelper.GetClaim(System.Security.Claims.ClaimTypes.GivenName, identity);
        }
    }
}
